home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML Authority.sea / XML Authority / Required / RC.jar / com / extensibility / app / ApplicationPreferences.class (.txt) next >
Encoding:
Java Class File  |  2000-07-05  |  9.1 KB  |  447 lines

  1. package com.extensibility.app;
  2.  
  3. import com.extensibility.util.Debug;
  4. import com.extensibility.xml.URI;
  5. import java.awt.Component;
  6. import java.awt.Font;
  7. import java.io.File;
  8. import java.io.FileInputStream;
  9. import java.io.FileNotFoundException;
  10. import java.io.FileOutputStream;
  11. import java.io.IOException;
  12. import java.io.OutputStream;
  13. import java.util.Enumeration;
  14. import java.util.Hashtable;
  15. import java.util.Properties;
  16. import java.util.Vector;
  17.  
  18. public class ApplicationPreferences extends Properties {
  19.    public static final String PREF_FILENAME = "_Preferences";
  20.    public static final String RECENT = "RECENT.";
  21.    public static final String RECENT_1 = "RECENT.1";
  22.    public static final String RECENT_2 = "RECENT.2";
  23.    public static final String RECENT_3 = "RECENT.3";
  24.    public static final String RECENT_4 = "RECENT.4";
  25.    public static final String RECENT_5 = "RECENT.5";
  26.    public static final String PLATFORM = "os.name";
  27.    public static final String MACOS = "Mac";
  28.    public static final String USER_NAME_CODE = "ESB";
  29.    public static final String ORGANIZATION_CODE = "KKB";
  30.    public static final String EMAIL_CODE = "EMC";
  31.    public static final String PHONE_CODE = "PHC";
  32.    public static final String SN_CODE = "CAB";
  33.    public static final String LAUNCHES_LEFT = "EGB";
  34.    public static final String REG_SENT = "RGS";
  35.    public static final String OEM_PARTNER_KEY = "OEM";
  36.    public static final String TOOLBAR_VIEW = "TOOLBAR.VIEW";
  37.    public static final String ONLINE_HELP = "ONLINE.HELP";
  38.    public static final String EXTERNAL_HELP_BROWSER = "EXTERNAL.HELP.BROWSER";
  39.    public static final String SHOW_WELCOME = "SHOW.WELCOME";
  40.    public static final String SHOW_LEFT_PANE = "SHOW.PANE.LEFT";
  41.    public static final String SHOW_BOTTOM_PANE = "SHOW.PANE.BOTTOM";
  42.    public static final String LOOK_AND_FEEL = "LOOK.AND.FEEL";
  43.    public static final String DEBUG_LEVEL = "DEBUG.LEVEL";
  44.    public static final String BROWSER_PATH = "BROWSER.PATH";
  45.    public static final String BROWSER_TYPE = "BROWSER.TYPE";
  46.    public static final String INTEGRATION_PORT = "INTEGRATION.PORT";
  47.    public static final String OPEN_FROM_BASE = "OPEN.FROM.BASE";
  48.    public static final String SAVE_TO_BASE = "SAVE.TO.BASE";
  49.    public static final String APP_FONT = "APP.FONT";
  50.    public static final String DOC_FONT = "DOC.FONT";
  51.    public static final String SRC_FONT = "SRC.FONT";
  52.    public static final String LEFT_MARGIN = "MARGIN.LEFT";
  53.    public static final String RIGHT_MARGIN = "MARGIN.RIGHT";
  54.    public static final String TOP_MARGIN = "MARGIN.TOP";
  55.    public static final String BOTTOM_MARGIN = "MARGIN.BOTTOM";
  56.    public static final String PRINT_PREF_ORIENTATION = "PRINT.PREF.ORIENTATION";
  57.    public static final String PRINT_PREF_WIDTH = "PRINT.PREF.WIDTH";
  58.    public static final String PRINT_PREF_HEIGHT = "PRINT.PREF.HEIGHT";
  59.    public static final String PRINT_PREF_IMAGEABLE_X = "PRINT.PREF.IMAGEABLE.X";
  60.    public static final String PRINT_PREF_IMAGEABLE_Y = "PRINT.PREF.IMAGEABLE.Y";
  61.    public static final String PRINT_PREF_IMAGEABLE_WIDTH = "PRINT.PREF.IMAGEABLE.WIDTH";
  62.    public static final String PRINT_PREF_IMAGEABLE_HEIGHT = "PRINT.PREF.IMAGEABLE.HEIGHT";
  63.    public static final String NUMS = "NUMS";
  64.    public static final String TRUE = "TRUE";
  65.    public static final String FALSE = "FALSE";
  66.    public static final String ASK = "ASK";
  67.    private static final int[] LAUNCH_CODES = new int[]{17054, 17296, 15217, 18688, 13450, 13015, 14645, 13151, 14322, 10118, 16682, 19513, 10317, 19393, 19578, 11150, 16933, 17466, 14093, 13906, 12261, 13193, 14278, 13754, 14009, 16575, 10757, 16949, 19035, 10161, 16504, 12686, 15379, 12956, 15133, 18256, 16795, 16826, 11671, 16703, 19780, 15404, 15842, 16975, 13106, 15497, 17849, 16589, 19852, 10993, 16657, 16781, 11936, 19265, 10768, 10163, 17143, 10081, 11509, 10882, 18661, 17003, 18810, 17272, 17108, 11304, 19485, 17017, 15065, 18363, 18015, 14798, 14108, 16581, 19828, 12457, 14336, 18780, 17080, 11651, 16407, 16114, 16938, 19004, 16067, 14471, 12358, 13772, 11180, 13383, 15370, 15370};
  68.    public static final String SOX_SCHEMA_PATH = "SOX.SCHEMA.PATH";
  69.    static File file;
  70.    public static final String DEFAULT_FILE_TYPE = "DEFAULT.FILE.TYPE";
  71.  
  72.    public void readInitial(File var1) {
  73.       FileInputStream var2 = null;
  74.  
  75.       try {
  76.          if (file == null) {
  77.             file = var1;
  78.          }
  79.  
  80.          var2 = new FileInputStream(file);
  81.          ((Properties)this).load(var2);
  82.          var2.close();
  83.       } catch (FileNotFoundException var5) {
  84.          this.initialize();
  85.       } catch (IOException var6) {
  86.          DialogFactory.showException((Component)null, 121, var6);
  87.          this.initialize();
  88.          if (var2 != null) {
  89.             try {
  90.                var2.close();
  91.             } catch (IOException var4) {
  92.             }
  93.          }
  94.       }
  95.  
  96.    }
  97.  
  98.    private void initialize() {
  99.       ((Hashtable)this).put("RECENT.1", "");
  100.       ((Hashtable)this).put("RECENT.2", "");
  101.       ((Hashtable)this).put("RECENT.3", "");
  102.       ((Hashtable)this).put("RECENT.4", "");
  103.       ((Hashtable)this).put("RECENT.5", "");
  104.       ((Hashtable)this).put("ESB", "");
  105.       ((Hashtable)this).put("KKB", "");
  106.       ((Hashtable)this).put("CAB", "");
  107.       ((Hashtable)this).put("SHOW.WELCOME", "TRUE");
  108.       ((Hashtable)this).put("ONLINE.HELP", "TRUE");
  109.  
  110.       try {
  111.          this.save();
  112.       } catch (IOException var2) {
  113.          ((Throwable)var2).printStackTrace();
  114.          DialogFactory.showException((Component)null, 108, var2);
  115.       }
  116.  
  117.    }
  118.  
  119.    public void save() throws IOException {
  120.       FileOutputStream var1 = null;
  121.  
  122.       try {
  123.          var1 = new FileOutputStream(file);
  124.          ((Properties)this).save(var1, UI.getString("splash.title") + " preferences");
  125.       } finally {
  126.          if (var1 != null) {
  127.             ((OutputStream)var1).close();
  128.          }
  129.  
  130.       }
  131.  
  132.    }
  133.  
  134.    public String getLookAndFeel() {
  135.       String var1 = ((Properties)this).getProperty("LOOK.AND.FEEL");
  136.       if (var1 == null) {
  137.          String var2 = System.getProperty("os.name");
  138.          return var2.startsWith("Mac") ? "it.unitn.ing.swing.plaf.macos.MacOSLookAndFeel" : "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
  139.       } else {
  140.          return var1;
  141.       }
  142.    }
  143.  
  144.    public void updateLookAndFeel(String var1) {
  145.       ((Hashtable)this).put("LOOK.AND.FEEL", var1);
  146.    }
  147.  
  148.    public Font getAppFont() {
  149.       String var1 = (String)((Hashtable)this).get("APP.FONT");
  150.       return var1 == null ? new Font("SansSerif", 0, 11) : Font.decode(var1);
  151.    }
  152.  
  153.    public void updateAppFont(Font var1) {
  154.       ((Hashtable)this).put("APP.FONT", var1.getName() + "-" + var1.getSize());
  155.    }
  156.  
  157.    public Font getDocFont() {
  158.       String var1 = (String)((Hashtable)this).get("DOC.FONT");
  159.       return var1 == null ? null : Font.decode(var1);
  160.    }
  161.  
  162.    public void updateDocFont(Font var1) {
  163.       ((Hashtable)this).put("DOC.FONT", var1.getName() + "-" + var1.getSize());
  164.    }
  165.  
  166.    public void updateDocFont(int var1) {
  167.       if (var1 == -1) {
  168.          ((Hashtable)this).remove("DOC.FONT");
  169.       } else {
  170.          Font var2 = this.getDocFont();
  171.          String var3 = var2 == null ? "SansSerif" : var2.getName();
  172.          ((Hashtable)this).put("DOC.FONT", var3 + "-" + var1);
  173.       }
  174.  
  175.    }
  176.  
  177.    public Font getSrcFont() {
  178.       String var1 = (String)((Hashtable)this).get("SRC.FONT");
  179.       return var1 == null ? null : Font.decode(var1);
  180.    }
  181.  
  182.    public void updateSrcFont(Font var1) {
  183.       ((Hashtable)this).put("SRC.FONT", var1.getName() + "-" + var1.getSize());
  184.    }
  185.  
  186.    public int getLaunchesLeft() {
  187.       String var1 = ((Properties)this).getProperty("EGB");
  188.       if (var1 == null) {
  189.          return 0;
  190.       } else {
  191.          int var2 = Integer.valueOf(var1);
  192.  
  193.          for(int var3 = 0; var3 < LAUNCH_CODES.length; ++var3) {
  194.             if (LAUNCH_CODES[var3] == var2) {
  195.                return var3;
  196.             }
  197.          }
  198.  
  199.          return 0;
  200.       }
  201.    }
  202.  
  203.    public void updateLaunchesLeft(int var1) {
  204.       Debug.assert(var1 >= 0 && var1 < LAUNCH_CODES.length, "invalid newLeft: " + var1);
  205.       ((Hashtable)this).put("EGB", (new Integer(LAUNCH_CODES[var1])).toString());
  206.  
  207.       try {
  208.          this.save();
  209.       } catch (Exception var2) {
  210.       }
  211.  
  212.    }
  213.  
  214.    public void initTrialLaunchesLeft(int var1) {
  215.       ((Hashtable)this).put("EGB", (new Integer(LAUNCH_CODES[var1])).toString());
  216.    }
  217.  
  218.    public boolean getOnlineHelp() {
  219.       String var1 = ((Properties)this).getProperty("ONLINE.HELP");
  220.       return var1 == null ? false : Boolean.valueOf(var1);
  221.    }
  222.  
  223.    public void updateOnlineHelp(boolean var1) {
  224.       ((Hashtable)this).put("ONLINE.HELP", (new Boolean(var1)).toString());
  225.    }
  226.  
  227.    public boolean getShowWelcome() {
  228.       String var1 = ((Properties)this).getProperty("SHOW.WELCOME");
  229.       return var1 == null ? true : Boolean.valueOf(var1);
  230.    }
  231.  
  232.    public void updateShowWelcome(boolean var1) {
  233.       ((Hashtable)this).put("SHOW.WELCOME", (new Boolean(var1)).toString());
  234.    }
  235.  
  236.    public boolean getShowLeftPane() {
  237.       String var1 = ((Properties)this).getProperty("SHOW.PANE.LEFT");
  238.       return var1 == null ? false : Boolean.valueOf(var1);
  239.    }
  240.  
  241.    public void updateShowLeftPane(boolean var1) {
  242.       ((Hashtable)this).put("SHOW.PANE.LEFT", (new Boolean(var1)).toString());
  243.    }
  244.  
  245.    public boolean getShowBottomPane() {
  246.       String var1 = ((Properties)this).getProperty("SHOW.PANE.BOTTOM");
  247.       return var1 == null ? false : Boolean.valueOf(var1);
  248.    }
  249.  
  250.    public void updateShowBottomPane(boolean var1) {
  251.       ((Hashtable)this).put("SHOW.PANE.BOTTOM", (new Boolean(var1)).toString());
  252.    }
  253.  
  254.    public String[] getMargins() {
  255.       String[] var1 = new String[4];
  256.       String var2 = ((Properties)this).getProperty("MARGIN.LEFT");
  257.       if (var2 == null) {
  258.          var1[2] = "60";
  259.       } else {
  260.          var1[2] = var2;
  261.       }
  262.  
  263.       String var3 = ((Properties)this).getProperty("MARGIN.RIGHT");
  264.       if (var3 == null) {
  265.          var1[3] = "60";
  266.       } else {
  267.          var1[3] = var3;
  268.       }
  269.  
  270.       String var4 = ((Properties)this).getProperty("MARGIN.TOP");
  271.       if (var4 == null) {
  272.          var1[0] = "60";
  273.       } else {
  274.          var1[0] = var4;
  275.       }
  276.  
  277.       String var5 = ((Properties)this).getProperty("MARGIN.BOTTOM");
  278.       if (var5 == null) {
  279.          var1[1] = "60";
  280.       } else {
  281.          var1[1] = var5;
  282.       }
  283.  
  284.       return var1;
  285.    }
  286.  
  287.    public int getDebugLevel() {
  288.       String var1 = (String)((Hashtable)this).get("DEBUG.LEVEL");
  289.       if (var1 == null) {
  290.          return 0;
  291.       } else {
  292.          int var2 = Integer.valueOf(var1);
  293.          return var2;
  294.       }
  295.    }
  296.  
  297.    public String getBrowserPath() {
  298.       String var1 = (String)((Hashtable)this).get("BROWSER.PATH");
  299.       return var1;
  300.    }
  301.  
  302.    public int getBrowserType() {
  303.       String var1 = (String)((Hashtable)this).get("BROWSER.TYPE");
  304.       if (var1 == null) {
  305.          return 0;
  306.       } else {
  307.          int var2 = Integer.valueOf(var1);
  308.          return var2;
  309.       }
  310.    }
  311.  
  312.    public String getOpenFromBase() {
  313.       String var1 = (String)((Hashtable)this).get("OPEN.FROM.BASE");
  314.       return var1;
  315.    }
  316.  
  317.    public void updateOpenFromBase(String var1) {
  318.       ((Hashtable)this).put("OPEN.FROM.BASE", var1);
  319.    }
  320.  
  321.    public String getSaveToBase() {
  322.       String var1 = (String)((Hashtable)this).get("SAVE.TO.BASE");
  323.       return var1;
  324.    }
  325.  
  326.    public void updateSaveToBase(String var1) {
  327.       ((Hashtable)this).put("SAVE.TO.BASE", var1);
  328.    }
  329.  
  330.    public void updateDebugLevel(int var1) {
  331.       ((Hashtable)this).put("DEBUG.LEVEL", (new Integer(var1)).toString());
  332.    }
  333.  
  334.    public void updateBrowserPath(String var1) {
  335.       if (var1 != null && var1.length() != 0) {
  336.          ((Hashtable)this).put("BROWSER.PATH", var1);
  337.       } else {
  338.          ((Hashtable)this).remove("BROWSER.PATH");
  339.       }
  340.  
  341.    }
  342.  
  343.    public void updateMargins(String[] var1) {
  344.       ((Hashtable)this).put("MARGIN.LEFT", var1[2]);
  345.       ((Hashtable)this).put("MARGIN.RIGHT", var1[3]);
  346.       ((Hashtable)this).put("MARGIN.TOP", var1[0]);
  347.       ((Hashtable)this).put("MARGIN.BOTTOM", var1[1]);
  348.    }
  349.  
  350.    public int getToolbarView() {
  351.       String var1 = ((Properties)this).getProperty("TOOLBAR.VIEW");
  352.       return var1 == null ? 1 : Integer.parseInt(var1);
  353.    }
  354.  
  355.    public void updateToolBarView(int var1) {
  356.       ((Hashtable)this).put("TOOLBAR.VIEW", (new Integer(var1)).toString());
  357.    }
  358.  
  359.    public void removeFromRecent(URI var1) {
  360.       String var2 = var1.getFullName();
  361.  
  362.       for(int var3 = 1; var3 <= 5; ++var3) {
  363.          String var4 = ((Properties)this).getProperty("RECENT." + var3);
  364.          if (var4 != null && var4.equals(var2)) {
  365.             ((Hashtable)this).remove("RECENT." + var3);
  366.             break;
  367.          }
  368.       }
  369.  
  370.       Vector var9 = new Vector();
  371.  
  372.       for(int var5 = 1; var5 <= 5; ++var5) {
  373.          String var6 = ((Properties)this).getProperty("RECENT." + var5);
  374.          if (var6 != null) {
  375.             var9.addElement(var6);
  376.             ((Hashtable)this).remove("RECENT." + var5);
  377.          }
  378.       }
  379.  
  380.       int var10 = 1;
  381.       Enumeration var7 = var9.elements();
  382.  
  383.       while(var7.hasMoreElements()) {
  384.          ((Hashtable)this).put("RECENT." + var10++, (String)var7.nextElement());
  385.       }
  386.  
  387.       try {
  388.          this.save();
  389.       } catch (Exception var8) {
  390.       }
  391.  
  392.    }
  393.  
  394.    public void updateRecent(URI var1) {
  395.       String var3 = var1.getFullName();
  396.  
  397.       int var2;
  398.       for(var2 = 5; var2 > 0; --var2) {
  399.          String var4 = ((Properties)this).getProperty("RECENT." + var2);
  400.          if (var4 != null && var4.equals(var3)) {
  401.             return;
  402.          }
  403.       }
  404.  
  405.       if (var2 == 0) {
  406.          for(int var8 = 5; var8 > 1; --var8) {
  407.             String var5 = ((Properties)this).getProperty("RECENT." + (var8 - 1));
  408.             if (var5 != null) {
  409.                ((Hashtable)this).put("RECENT." + var8, var5);
  410.             }
  411.          }
  412.  
  413.          var2 = 1;
  414.       }
  415.  
  416.       ((Hashtable)this).put("RECENT.1", var3);
  417.  
  418.       try {
  419.          this.save();
  420.       } catch (Exception var6) {
  421.       }
  422.  
  423.    }
  424.  
  425.    public String getDefaultFileType() {
  426.       String var1 = (String)((Hashtable)this).get("DEFAULT.FILE.TYPE");
  427.       if (var1 == null) {
  428.          var1 = UI.getString("com.extensibility.app.defaultfiletype");
  429.       }
  430.  
  431.       return var1;
  432.    }
  433.  
  434.    public void updateDefaultFileType(String var1) {
  435.       ((Hashtable)this).put("DEFAULT.FILE.TYPE", var1);
  436.    }
  437.  
  438.    public String getSchemaPath() {
  439.       String var1 = (String)((Hashtable)this).get("SOX.SCHEMA.PATH");
  440.       return var1;
  441.    }
  442.  
  443.    public void updateSchemaPath(String var1) {
  444.       ((Hashtable)this).put("SOX.SCHEMA.PATH", var1);
  445.    }
  446. }
  447.